package xyz.xmh.pattern.structural.compositepattern;

/**
 * CompositePatternDemo
 * 组合模式演示<br/>
 * 适合树形结构，如树形菜单、文件夹。。。
 *
 * @author xuMingHai
 * @since 2021/4/30 星期五 16:43
 */
public class CompositePatternDemo {

    public static void main(String[] args) {
        // CEO
        Employee ceo = new Employee("张三", "CEO", 50000);

        // CEO的直接下属：
        // 首席销售
        Employee headSales = new Employee("李四", "Head Sales", 30000);
        // 营销主管
        Employee headMarketing = new Employee("王五", "Head Marketing", 30000);

        // 营销主管的直接下属
        // 店员
        Employee clerk1 = new Employee("赵六", "Marketing", 10000);
        Employee clerk2 = new Employee("田七", "Marketing", 10000);

        // 首席销售的直接下属
        // 销售
        Employee sales1 = new Employee("王八", "Sales", 8000);
        Employee sales2 = new Employee("柳九", "Sales", 8000);

        // 添加下属
        ceo.addSub(headSales);
        ceo.addSub(headMarketing);

        headSales.addSub(sales1);
        headSales.addSub(sales2);

        headMarketing.addSub(clerk1);
        headMarketing.addSub(clerk2);

        // 打印这家店的所有人员
        System.out.println(ceo);

        for (Employee headEmployee : ceo.getEmployeeList()) {
            System.out.println(headEmployee);

            for (Employee employee : headEmployee.getEmployeeList()) {
                System.out.println(employee);
            }
        }

    }

}
